//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __CGZIPOUTPUTSTREAM_H__
#define __CGZIPOUTPUTSTREAM_H__

#include "_CGZipOutputStream.h"
#include "zlib.h"

CarClass(CGZipOutputStream)
{
public:
    CGZipOutputStream(): m_pIos(NULL), m_pBuf(NULL) {}

    ~CGZipOutputStream();

    CARAPI constructor(
        /* [in] */ IOutputStream * pStream);

    CARAPI constructor(
        /* [in] */ IOutputStream * pStream,
        /* [in] */ Int32 windowBits,
        /* [in] */ Int32 compressLevel,
        /* [in] */ Int32 memoryUsageLevel,
        /* [in] */ CompressStrategy strategy);

    CARAPI constructor(
        /* [in] */ IOutputStream * pStream,
        /* [in] */ Int32 windowBits,
        /* [in] */ Int32 compressLevel,
        /* [in] */ Int32 memoryUsageLevel,
        /* [in] */ CompressStrategy strategy,
        /* [in] */ const BufferOf<Byte> & dictionary);

    CARAPI Close();

    CARAPI Flush();

    CARAPI Write(
        /* [in] */ Byte value);

    CARAPI WriteBuffer(
        /* [in] */ const BufferOf<Byte> & buffer,
        /* [out] */ Int32 * pBytesWritten);

    CARAPI WriteBufferEx(
        /* [in] */ Int32 offset,
        /* [in] */ Int32 length,
        /* [in] */ const BufferOf<Byte> & buffer,
        /* [out] */ Int32 * pBytesWritten);

private:
    ECode DeflateStream(
        Byte * pBuffer,
        Int32 bufferSize,
        Int32 *pCount);

private:
    IOutputStream * m_pIos;
    BufferOf<Byte>* m_pBuf;
    z_stream m_stream;
};

#endif // __CGZIPOUTPUTSTREAM_H__
